<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body></body>
  <script>
    const sleep = (ms) => {
      return new Promise((resolve) => {
        setTimeout(() => {
          resolve();
        }, ms);
      });
    };
    const loadImg = (url) => {
      return new Promise((resolve, reject) => {
        let img = new Image();
        img.src = url;
        img.onload = () => {
          resolve(img);
        };
        img.onerror = () => {
          reject(new Error("e"));
        };
      });
    };
    const getImg = async () => {
      await sleep(3000);

      const element = await loadImg(
        "https://placekitten.com/cdn-cgi/images/cf-icon-ok.png"
      );
      console.log("element", element);
      document.body.appendChild(element);
    };
    getImg();
  </script>
</html>
